package eoeProject.edenOfEast.core;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SQLExp {

	private String sql = "";
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	public SQLExp() {

	}

	public void setExpEquals(String column, String value) {
		sql = (" " + column + " is not null AND " + column + " = '" + value + "' ");
	}

	public void setExpEquals(String column, Date value) {
		setExpEquals(column, sdf.format(value));
	}

	public void setExpEquals(String column, Integer value) {
		setExpEquals(column, value.toString());
	}

	public void setExpLike(String column, String value) {
		sql = (" " + column + " is not null AND " + column + " LIKE '%" + value + "%' ");
	}

	public void setExpLike(String column, Date value) {
		setExpLike(column, sdf.format(value));
	}

	public void setExpLike(String column, Integer value) {
		setExpLike(column, value.toString());
	}

	public void setExpNotEquals(String column, String value) {
		sql = (" " + column + " is not null AND " + column + " != '" + value + "' ");
	}

	public void setExpNotEquals(String column, Date value) {
		setExpNotEquals(column, sdf.format(value));
	}

	public void setExpNotEquals(String column, Integer value) {
		setExpNotEquals(column, value.toString());
	}

	public void jointExpAnd(SQLExp exp) {
		sql = "(" + sql + ") AND " + exp.getExpValue();
	}

	public void jointExpOr(SQLExp exp) {
		sql = sql + " OR " + exp.getExpValue();
	}

	public String getExpValue() {
		return "(" + sql + ")";
	}
}
